import { Style, Fill, Text, Icon } from 'ol/style';
import { mapManager } from '../MapManager';
import dotImg from '@/assets/map/add_dot.png'
import Circle from 'ol/style/Circle';
import Stroke from 'ol/style/Stroke';


var FACILITYS_Z = 740;

/**
 * 设施样式的封装类
 */
class FacilityStyle {

    /**
     * 获取地块样式
     * @public
     * @param {import("../../../util/typedef").FacilityInfo} facility   设备信息
     * @return {import('ol/style/Style').StyleFunction} 返回样式
     */
    static getStyle(facility) {
        return function (feature) {


            var zoom = mapManager.getMap().getView().getZoom();
            var fontSize = 12;
            var scale = 1;


            if (zoom < 15.1) {
                fontSize = 0;
                scale = 0;
            } else {
                fontSize = 12;
                scale = 1;
            }

            var blue = [0, 153, 255, 1];
            var blue2 = [0, 153, 255, 0.5];
            var width = 3;
            var style = new Style({
                image: new Circle({
                    radius: width * 2,
                    fill: new Fill({
                        color: blue2
                    }),
                    stroke: new Stroke({
                        color: blue,
                    }),
                    scale: scale
                }),
                text: new Text({
                    font: fontSize + "px 宋体",
                    fill: new Fill({
                        color: "#fff"
                    }),
                    textBaseline: "top",
                    text: facility.name,
                    offsetY: 6
                }),
                zIndex: FACILITYS_Z + 1
            })

            return style;
        }


    }
    /**
     * 画样式
     */
    static drawfacility() {
        return new Style({
            image: new Icon(({
                anchor: [0.5, 27],
                anchorXUnits: 'fraction', //分数
                anchorYUnits: 'pixels',//像素
                src: dotImg
            })),
        })
    }


}


export default FacilityStyle;